package cmd

import (
	"strings"

	"gitee.com/qianyucc/secure-tool/util"

	gouuid "github.com/satori/go.uuid"
	"github.com/spf13/cobra"
)

var (
	ReplaceMinus bool
)

// uuidCmd represents the uuid command
var uuidCmd = &cobra.Command{
	Use:   "uuid",
	Short: "Generate UUID use version4 default",
	Long:  `Generate UUID use version4 default`,
	Run: func(cmd *cobra.Command, args []string) {
		u1 := gouuid.NewV4()
		uuidStr := u1.String()
		if ReplaceMinus {
			uuidStr = strings.ReplaceAll(uuidStr, "-", "")
		}
		if IsUpperCase {
			uuidStr = strings.ToUpper(uuidStr)
		}
		util.PrintAndCopyTextToClipboardIgnoreError(uuidStr)
	},
}

func init() {
	rootCmd.AddCommand(uuidCmd)
	uuidCmd.Flags().BoolVarP(&ReplaceMinus, "replace", "r", false, `Replace the character "-" with a space`)
	uuidCmd.Flags().BoolVarP(&IsUpperCase, "upperCase", "u", false, "Indicates whether the result is upper case")
}
